package cn.hd.shop_springboot.service.impl;

import cn.hd.shop_springboot.mapper.UserMapper;
import cn.hd.shop_springboot.pojo.User;
import cn.hd.shop_springboot.pojo.UserExample;
import cn.hd.shop_springboot.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public void add(User user) {
        userMapper.insert(user);
    }

    @Override
    public void update(User user) {
        UserExample example = new UserExample();
        example.createCriteria().andUseridEqualTo(user.getUserid());
        userMapper.updateByExampleSelective(user,example);
    }

    @Override
    public void delete(int id) {
        UserExample example = new UserExample();
        example.createCriteria().andUseridEqualTo(id);
        userMapper.deleteByExample(example);
    }

    @Override
    public User get(int id) {
//        UserExample example = new UserExample();
//        example.createCriteria().andUseridEqualTo(id);
        return userMapper.get(id);
    }

    @Override
    public List<User> list() {
        return userMapper.list();
    }
}
